package com.ld.control.business.process.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ld.control.business.process.model.ProcessTmpModel;
import com.ld.control.business.process.service.ProcessTmpService;
import com.ld.control.business.process.vo.req.ProcessTmpReqVo;
import com.ld.control.business.process.vo.resp.ProcessTmpRespVo;
import com.ld.control.common.ResultResponse;
import com.ld.control.common.vo.GenerateListVo;
import com.ld.control.common.vo.GeneratePageListVo;
import com.ld.control.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 任务流程模板 前端控制器
 * </p>
 *
 * @author wangfeng
 * @since 2024-04-24
 */
@Slf4j
@Tag(name = "流程模板相关接口")
@RestController
public class ProcessTmpController {

    @Autowired
    private ProcessTmpService processTmpService;

    @GetMapping("/api/centralControl/processTmp/getPageList")
    @Operation(summary = "流程模板列表(带分页)")
    public ResultResponse<GeneratePageListVo<ProcessTmpRespVo>> getPageList(
            @RequestParam(required = false) Long regionId,
            @RequestParam(required = false) String name,
            @Parameter(description = "流程模板类型：0普通流程，1:初始化流程，2结束流程，3内部流程") @RequestParam(required = false) Integer type,
            @RequestParam(required = false, defaultValue = "1") Integer current,
            @RequestParam(required = false, defaultValue = "9999") Integer size
    ) {
        IPage<ProcessTmpRespVo> iPage = processTmpService.getPageList(regionId, name, type, current, size);
        return ResultResponse.success(new GeneratePageListVo<>(iPage));
    }

    @GetMapping("/api/centralControl/processTmp/getAllList")
    @Operation(summary = "流程模板列表(不带分页)")
    public ResultResponse<GenerateListVo<ProcessTmpRespVo>> getPageList(
            @RequestParam(required = false) Long regionId,
            @RequestParam(required = false) String name,
            @Parameter(description = "流程模板类型：0普通流程，1:初始化流程，2结束流程，3内部流程") @RequestParam(required = false) Integer type
    ) {
        List<ProcessTmpRespVo> iPage = processTmpService.getAllList(regionId, name, type);
        return ResultResponse.success(new GenerateListVo<>(iPage));
    }

    @GetMapping("/api/centralControl/processTmp/getById")
    @Operation(summary = "获取流程模板详情")
    public ResultResponse<ProcessTmpRespVo> getById(
            @RequestParam Long id
    ) {
        ProcessTmpRespVo processTmpRespVo = processTmpService.getById(id);
        return ResultResponse.success(processTmpRespVo);
    }

    @PostMapping("/api/centralControl/processTmp/deleteById")
    @Operation(summary = "删除流程模板")
    public ResultResponse<ResultResponseEnum> deleteById(
            @RequestParam Long id
    ) {
         processTmpService.deleteById(id);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/processTmp/add")
    @Operation(summary = "添加流程模板")
    public ResultResponse<ResultResponseEnum> add(
            @RequestBody ProcessTmpReqVo processTmpReqVo
    ) {
        processTmpService.add(processTmpReqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/processTmp/update")
    @Operation(summary = "修改流程模板")
    public ResultResponse<ResultResponseEnum> update(
            @RequestBody ProcessTmpReqVo processTmpReqVo
    ) {
        processTmpService.update(processTmpReqVo);
        return ResultResponse.success();
    }

}

